using System;
using System.Collections.Generic;
using System.Data;
using MallInteractiveMap.ClientDataHandler;
using MallInteractiveMap.Common;
using MallInteractiveMap.DTO;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient.Presenter
{
	public class CategoryPresenter
	{
		public CategoryPresenter()
		{
		}
		public List<DTOCategory> GetCategorys()
		{
			string error = string.Empty;
			List<DTOCategory>category= ClientData.GetCategory(new QueryParamList(), ref error);
			if (!string.IsNullOrEmpty(error))
			{

			}
			return category;
		}
		public List<DTOCategory> GetCategorys(int Id)
		{
			string error = string.Empty;
			QueryParamList param = new QueryParamList();
			param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32 , ParamValue = Id});
			List<DTOCategory>category= ClientData.GetCategory(param, ref error);
			if (!string.IsNullOrEmpty(error))
			{

			}
			return category;
		}
		public bool SetData(DTOCategory oCategory)
		{
			QueryParamList param = new QueryParamList();
            if (!oCategory.IsNew)
            {
                param.Add(new QueryParamObj() {ParamName = "Id", DBType = DbType.Int32, ParamValue = oCategory.Id});
            }
            else
            {
                param.Add(new QueryParamObj() { ParamName = "LanguageType", DBType = DbType.Int32, ParamValue = LanguageLoader.CurrentLanguageType });
            }
            
            
		    param.Add(new QueryParamObj(){ParamName="Name", DBType=DbType.String, ParamValue= oCategory.Name});
			param.Add(new QueryParamObj(){ParamName="Description", DBType=DbType.String, ParamValue= oCategory.Description});
			param.Add(new QueryParamObj(){ParamName="LastUpdated", DBType=DbType.DateTime, ParamValue= oCategory.LastUpdated});
			string error = string.Empty;
			string spName = oCategory.IsNew ? "INSERTCategory " : "UPDATECategory";
			bool isSuccess = ClientData.SetData(param, spName, ref error);
			return string.IsNullOrEmpty(error) & isSuccess;
		}
		public bool Delete(int Id)
		{
			string error = string.Empty;
			QueryParamList param = new QueryParamList();
			param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32 , ParamValue = Id});
			bool isSuccess = ClientData.SetData(param, "DELETECategory",  ref error);
			return string.IsNullOrEmpty(error) & isSuccess;
		}

	    public bool IsShopAvailable(int categoryId)
	    {
	        return ClientData.IsShopAvailable(categoryId);
	    }
	}
}
